# -*- coding: utf-8 -*-

import time
import random


def relations(func):
    def wrapper(*args, **kwargs):
        args = list(args)
        # 面向对象的封装，第一个参数一定是self
        self = args[0]

        # 随机数
        int_r = random.randint(1, 999999999)
        str_r = '%09d' % int_r
        self.relations_dict['random'] = str_r
        # 时间戳
        t_str = str(int(time.time() * 1000))
        self.relations_dict['time'] = t_str

        # 然后遍历每一个参数，进行关联
        for i in range(1, len(args)):
            # 采用逆向
            # 把字典的键，拼成{key}的形式，去替换字符串里面的内容
            # print('这里就是实现算法')
            for key in self.relations_dict.keys():
                # print('{' + key + '}')
                args[i] = str(args[i]).replace('{' + key + '}', str(self.relations_dict.get(key)))

        # print(args)
        res = func(*args, **kwargs)
        return res

    return wrapper
